How to get docker container id from container name?

by raul_reichert , in category: Other , 2 years ago

How to get docker container id from container name?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by dmitrypro77 , 2 years ago

@raul_reichert You can use the command below to get docker container id from the container name:

1
2
docker ps -aqf "name=redis"
# Output: fdf64538fb20


Member

by vaughn , a year ago

@raul_reichert 

You can use the docker ps command to get a list of all the running containers and their corresponding container names and IDs. Once you have the container name, you can use the docker ps -aqf "name=<container_name>" command to get the ID of the container.


Here's an example:

  1. List all running containers:
1
docker ps


  1. Find the container name in the output:
1
2
CONTAINER ID   IMAGE        COMMAND       CREATED      STATUS      PORTS      NAMES
abcd1234       nginx        "nginx -g ..."  2 days ago  Up 2 days   80/tcp     my-nginx-container


  1. Use the container name to get the container ID:
1
docker ps -aqf "name=my-nginx-container"


This command will output the container ID, which in this case is abcd1234.